package com.lyshop.jinxiang.adapters;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.lyshop.jinxiang.R;
import com.lyshop.jinxiang.base.BaseActivity;
import com.lyshop.jinxiang.base.BaseRVAdapter;
import com.lyshop.jinxiang.base.BaseRVHolder;
import com.lyshop.jinxiang.base.BaseViewHolder;
import com.lyshop.jinxiang.bean.AddressBean;
import com.lyshop.jinxiang.utils.RouteUtil;

import java.util.List;

public class AddressListRVAdapter extends BaseRVAdapter<AddressBean> {

    public AddressListRVAdapter(Context context, List<AddressBean> list) {
        super(context, list);
    }

    @Override
    public int onCreateViewLayoutID(int viewType) {
        return R.layout.item_address_info;
    }

    @Override
    public void onBindView(BaseRVHolder holder, int position) {
        BaseViewHolder mHolder = holder.getViewHolder();
        TextView tv_user_info = mHolder.get(R.id.tv_user_info);
        TextView tv_user_address = mHolder.get(R.id.tv_user_address);
        ImageView iv_edit = mHolder.get(R.id.iv_edit);

        final AddressBean bean = mList.get(position);

        String user_info = bean.name + " " + bean.mobile;
        String address = bean.region + " " + bean.address;
        tv_user_info.setText(user_info);
        tv_user_address.setText(address);

        if (bean.is_default == 1) {
            tv_user_info.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.icon_tips_default, 0);
        } else {
            tv_user_info.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        }

        iv_edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RouteUtil.toAddAddressActivity((BaseActivity) mContext, bean);
            }
        });
    }
}
